/**
 * 
 */
package com.xbang.attendance.web.action.purchase.relateddevliery;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.order.PurchaseOrder;
import com.xbang.attendance.entity.system.Region;
import com.xbang.attendance.service.DeliveryOrderService;
import com.xbang.attendance.service.ProductService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.BaseActionSupport;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final Log logger = LogFactory.getLog(Search.class);

	private static final long serialVersionUID = -1120551442020217513L;
	@Autowired
	private ProductService productService;
	
	@Autowired
	private DeliveryOrderService deliveryOrderService;
	
	private List<PurchaseOrder> purchaseOrders = new ArrayList<PurchaseOrder>();
	
	private List<Region> regions = new ArrayList<Region>();

	@Override
	public String execute() throws Exception {
		logger.info("call default method - execute()");
		return "success";
	}

	@Action("/purchase/related/search")
	public String search() throws Exception {
		logger.info("request action : search");
		regions = deliveryOrderService.getObjects(Region.class);
		
		return "search";
	}
	
	@Action("/purchase/related/search/do")
	public String doSearch() throws Exception{
		
		String hqlSentence = " FROM PurchaseOrder purchaseorder WHERE 1 = 1 ";
		
		Result result = deliveryOrderService.searchByPage(hqlSentence, searchComponent, page);
		
		purchaseOrders = result.getItems();
		page = result.getPage();
		
		return "index";
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub
		
	}


	public ProductService getProductService() {
		return productService;
	}


	public void setProductService(ProductService productService) {
		this.productService = productService;
	}


	public DeliveryOrderService getDeliveryOrderService() {
		return deliveryOrderService;
	}


	public void setDeliveryOrderService(DeliveryOrderService deliveryOrderService) {
		this.deliveryOrderService = deliveryOrderService;
	}


	public List<PurchaseOrder> getPurchaseOrders() {
		return purchaseOrders;
	}


	public void setPurchaseOrders(List<PurchaseOrder> purchaseOrders) {
		this.purchaseOrders = purchaseOrders;
	}

	public List<Region> getRegions() {
		return regions;
	}

	public void setRegions(List<Region> regions) {
		this.regions = regions;
	}
	
	
	
}
